package com.lza.phone.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lza.phone.service.AliOssService;
import com.lza.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@Api(value="文件接口")
@RestController
public class UploadController {
    @Autowired
    AliOssService aliOssService;
    @ApiOperation("上传文件")
    @PostMapping("upload1")
    public Result upload(MultipartFile file){
        String upload = aliOssService.upload(file);
        return Result.ok().getMessage(upload);
    }

    @ApiOperation("列举文件")
    @ApiOperationSupport(author = "澳神弱爆")
    @GetMapping("/listFile")
    public Result listFile(){
        aliOssService.listFile();
        return Result.ok();
    }
    //上传文件，自己搞
    @ApiOperation("上传文件测试")
    @ApiOperationSupport(author = "澳神弱爆")
    @PostMapping("/fileUpload")
    public Result fileUpload(MultipartFile file, HttpServletRequest request){
        StringBuffer url = request.getRequestURL();
        System.out.println(url);
        String fileName = aliOssService.uploadFile(file);
        return Result.ok().getMessage(fileName);
    }

}
